# Create your views here.

from django.views import View

from server.utils import Response, Request, LoginRequiredPerson, Verify, Code


class InformationView(LoginRequiredPerson, View):
    """ User Personal Information """

    def get(self, request):
        """ Get user personal information """
        return Response.Json(infomation=request.user.info())

    @Request.getJson
    def post(self, request):
        """ Modifying User Personal Information """
        phone = request.JSON.get('phone')

        if phone != None:
            code = Verify.phone(phone)
            if code != Code.OK:
                return Response.Json(code=code)
            request.user.phone = phone

        request.user.save()
        return Response.Json()
